Add RawContainerReader: read the SPBXDS container without assuming OWON's JSON schema - #1
Open
alexlegoshin wants to merge 1 commit into
Open
Conversation
…ON's JSON schema BinfileReader throws on capture files whose JSON metadata doesn't match the OWON/Hanmatek schema it expects. An AKIP-4122/7 capture, for example, uses the same SPBXDS container but a different JSON layout (lowercase `channel` array, Display_Switch/Reference_Zero/Voltage_Rate instead of CHANNEL/DISPLAY/Current_Ratio/Current_Rate) and includes a trailing comma before the array's closing bracket, which makes System.Text.Json throw: System.Text.Json.JsonException: The JSON array contains a trailing comma at the end which is not supported in this mode. Change the reader options. RawContainerReader parses only the vendor-agnostic parts of the container -- magic header, JSON length, JSON text (untouched, no assumptions about its schema), one Int16[] per data segment, and the optional trailing INFO block -- so callers can interpret non-OWON metadata themselves instead of hitting this exception. BinfileReader is untouched; this is purely additive. Includes a real AKIP-4122/7 capture as a test fixture and tests covering both the AKIP and OWON containers, plus the existing error paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BinfileReaderassumes every.binfile's JSON metadata follows the OWON/Hanmatekschema (
CHANNEL/DISPLAY/Current_Ratio/Current_Rate, etc.). Files from otherscopes built on the same OEM platform can use the same
SPBXDScontainer but adifferent JSON layout — for example, an AKIP-4122/7 capture I ran into uses a
lowercase
channelarray withDisplay_Switch/Reference_Zero/Voltage_Ratefields instead, and its JSON has a trailing comma before the array's closing
bracket. Both of those make
BinfileReader.ReadAsyncthrow:So today there's no way to open such a file with this library at all, even though the
container itself is fully readable.
What this PR adds
A new, independent
RawContainerReaderthat parses only the vendor-agnostic parts ofthe
SPBXDScontainer — magic header, JSON length, the JSON text itself (returnedas-is, no assumptions about its schema or strictness), one
Int16[]per data segment,and the optional trailing
INFOblock:This lets callers handle files with a metadata schema
BinfileReaderdoesn'trecognize by parsing
RawJsonthemselves, instead of getting an exception with noworkaround.
BinfileReaderitself is completely untouched — this is a purely additive,opt-in alternative for the "I have a file this library can't parse" case, not a
replacement.
Testing
RawContainerReaderTests.cs: the AKIP-4122/7 fixture (singlesegment, no tail), the existing OWON fixture, a synthetic multi-segment +
INFO-tail case (to exercise segment-boundary/tail detection that no single realfixture covers), and the three existing error paths (invalid header, invalid JSON
size, stream not at position 0).
testfiles/akip.bin, a real capture from an AKIP-4122/7 (firmware V7.6.0),as a small (~20 KB) fixture.
Docs
Added a short new README section ("Reading files from other scopes on the same
platform") documenting
RawContainerReader, its motivation, and a usage example, rightbefore the existing
TestAppsection. No existing README content was changed.